const A = [
    [0, 1], [0, 2], [0, 3], [1, 0], [1, 2], [1, 3],
    [2, 0], [2, 1], [2, 3], [3, 0], [3, 1], [3, 2],
];
const B = [
    [0, 1, 2], [0, 1, 3], [0, 2, 1], [0, 2, 3], [0, 3, 1], [0, 3, 2],
    [1, 0, 2], [1, 0, 3], [1, 2, 0], [1, 2, 3], [1, 3, 0], [1, 3, 2],
    [2, 0, 1], [2, 0, 3], [2, 1, 0], [2, 1, 3], [2, 3, 0], [2, 3, 1],
    [3, 0, 1], [3, 0, 2], [3, 1, 0], [3, 1, 2], [3, 2, 0], [3, 2, 1],
];

const FS = [
    (p, n) => p & n,
    (p, n) => ~p & n,
    (p, n) => p & ~n,
    (p, n) => ~p & ~n,
    (p, n) => p | n,
    (p, n) => ~p | n,
    (p, n) => p | ~n,
    (p, n) => ~p | ~n,
    (p, n) => p ^ n,
    (p, n) => ~p ^ n,
    (p, n) => p ^ ~n,
    (p, n) => ~p ^ ~n,
]

let x, y, z, a, b, c;

/*
x:'0',y:'1',z:'_',a:'0',b:'1',c:'2'
(x,a) -> (x,a)
(x,b) -> (y,a)
(x,c) -> (x,b)
(y,a) -> (y,b)
(y,b) -> (x,c)
(y,c) -> (y,c)
(z,a) -> (z,a)
(z,b) -> (x,b)
(z,c) -> (z,c)
*/

const ck = (f1, f2, p1, n1, p2, n2) => (f1(p1, n1) === p2) && (f2(p1, n1) === n2);

(() => {
    let count = 0;
    for (const p of A) {
        for (const n of B) {
            // [x, y, z] = p;
            [x, y] = p;
            [a, b, c] = n;

            let rd = [
                [x, a, x, a], [x, b, y, a], [x, c, x, b],
                [y, a, y, b], [y, b, x, c], [y, c, y, c],
                // [z, a, z, a], [z, b, z, b], [z, c, z, c],
            ]

            for (const f1 of FS) {
                for (const f2 of FS) {

                    if (rd.some(k => !ck(f1, f2, k[0], k[1], k[2], k[3]))) continue;

                    count++;

                    console.log(`x:${x.toString(2)},y:${y.toString(2)},` +
                        `a:${a.toString(2)},b:${b.toString(2)},c:${c.toString(2)}`);
                    console.log(`f1:${f1.toString()}\nf2:${f2.toString()}`)

                    // if (count > 20) return null;
                }
            }
        }
    }

    console.log('count:', count);
})();